package com.lucker.service;

import java.util.Map;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisUtils {

	static JedisPool jedisPool = null;

	static {

		final String ip = "r-uf6cfc3e640dd254pd.redis.rds.aliyuncs.com";
		final int port = 6379;

		final JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxIdle(10000);
		final int tm = 3000;
		jedisPool = new JedisPool(config, ip, port, tm);
	}

	public synchronized static Jedis getJedis() {
		if (jedisPool != null) {
			// 获取资源
			Jedis resource = jedisPool.getResource();
			return resource;
		} else {
			return null;
		}
	}

	public static void returnBrokenResource(Jedis jedis) {
		if (jedis != null) {
			// 释放资源
			jedisPool.returnBrokenResource(jedis);

		}
	}

	public static void returnResource(Jedis jedis) {
		if (jedis != null) {
			// 释放资源
			jedisPool.returnResource(jedis);
		}
	}
	
	
	public static void hmset(String key,Map<String,String> map) {
		
		try {
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
//			returnResource();
		}
		
	}

}
